package com.data;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

@Component
public class HibernateSqlService extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(HibernateSqlService.class);

	@Autowired
	public void setDaoSessionFactory(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	
	public List find(String sql) {
		log.debug("finding by sql: " + sql);
		try {
			return getSession().createSQLQuery(sql).list();
		} catch (RuntimeException re) {
			log.error("find by sql failed", re);
			throw re;
		}
	}
}
